<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<script type="text/javascript">
var leaving = true;
function checkUrl(href) {
leaving = (((href.indexOf("://") > -1) || (href.indexOf("www.") > -1)) && (href.indexOf(window.location.host) == -1));
// add in more things to include in the line above as you see fit
}
function pop() {
if(leaving) window.open("demo.html");
}
window.onunload = pop;
var e = documents.getElementsByTagName("a");
for(var i=0;i<e.length;i++) e[i].onclick = "checkUrl(this.href)";
</script>
<a href="http://www.example.com/">Click here and you'll see a popup window</a>
<a href="internal.htm">Click here and you won't</a>
</body>
</html>